<?php

namespace app\common\model\pay;



use addons\recharge\model\Order;
use app\api\model\hotel\HotelThirdOrder;
use fast\Http;
use fast\Random;

class Pay
{
    //商户名称 杭州旅小二酒店管理有限公司（充值）

    //商户号  56433107011JKNU

    //appid 00377403



    public $cusRsaPrivateKey = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDFF0DIsr3MulJxMncCWzNutqFFXMm8xuYb5m5JZ7CSqKEvRCOTI3hANxg5zSVVYnRZgPGMce2pOFS8djagYW4Q/ChXiVPIEvxCQ5Vcqd/XxNwberFWqRMZiOdS+4vqJVbhd1NGu21qCU6ABN5uYJHCFfu3LqIsF/LMnvbm+SJ6STuO7RTrCSOPFqS1qFYmPEqP9NeOsmjNJ7fM74VIOZ9x0ySGcE+dj/aqWpMJlaxHhOp8yKEQ8SAZzM+rEgARB2I1GmZKeqPWWNuvD8hTagpkDhNfc+unKUGpZpdKAIe67SQCWKHhtLSulw3AswYoVwLvyqg9PUBB+4GxD8bTnARDAgMBAAECggEAK2NcmDI9NWI5PwFAkMy6DF/5Lddo8/2Hb9HxKojApvCnl0u1VzGCSgS2+RaP5vWnLoMD6gq0qsGjad/OU81PGT8htG+feZawYPgW3BDrnckROZ1vh+fts/vfDPYijZfNwhHuS858HlFRLj6kJwFsZSFIykFiYzmccm52ZU+oRuoQWSIu04lyAfHu3zvx+r/6U3ha5Am3jGMmYrr+6C4X5+L8yMLYswMgWSM3bYwi+x/0h21Qd7kXOjrJSq+V9bqsdpVM41S7sakPeolQZSbdrihzCdMK25OvNhM7Xr2J53Nc4hL73bvT9EimEVXpgNXEPj1wwTvv1vZaHix8ktE89QKBgQDnNQpTZBoiNWLH3b6fkzJefkQsuYvR5qW0NkB7iOjDfptMPbSAMSiWvnISgpozHg4/AR5xITWXg/CJ63n1BwSSyeKZmpI/OXWJXg3CIOfDAId0PE3g/yezmSuLOtsF6DXc0hppvWBX7BSdQwG0VKCWQ4PG1ZSY2KholXr5siMg5QKBgQDaOavSU59RERh7jz7+0vP4uvRqfH3RIAn2fui2T/tXScia+XyyKEwGY9jOceR+k/158be6SzXMd8Q869u09Ti9R65fpgo/d8fubzGmaFJNZ02ST/6utI8jIA8ol4KLbn5inyLHiQpZZ3tGBXFR/b46/WzhDknNe5Rk6MCEkhHGBwKBgAkmvkvisG4eMtS6YCssxlebI9OpXHFocbKaWx8Ioj3qqvbvkk9oorSkwRsedEAFtoaj4rKTn+1pWYH8Ag3Cw1mUCBYQWi2Kdq6DPIQsjT/Yq4PcRzDaqJWhQGn4YGbxdABTiJwa1M9mFsLKviyHFPwdm/+owIL0QGYzVHTBqkZJAoGAeBKbdBMG6jgZ3IKpCtVP4GAd9CmjoNmcIcEakpXXmePDOWJlNjHuAuYVeSI5s1wCcIKLsTmI1IRhuZOdRChZm+xBCef2Y42ouIz+KK3l+ykICaVyYPaAe7c8H/2dmtKlP+aH4HqK8z55GcIM5CxV62dd7UdLXIDO2ecnZspodSkCgYAMKVxUabDWh2XSxuLfwNt0aDnxOTLj1zg2W1k7lEEf3zIJkWA6DMYhWQSXKmuD+pIdk2oinzMkDRbScPRergNUJUHBpyBsHtzxr9q5GCcWtOZ2CCr6xpz8W8kFH7xhzND4Ig7Qw90X8gLb6CrjfRm6n7UfF3/UqvZ7T64WS0PWXg==";

    public $appid = "00377403";

    public $cusid = "56433107011JKNU";


    public function rechargepay($order_no)
    {
        $order = Order::get(['orderid'=>$order_no]);

        $reqsn = $order['orderid'];

        $request = request();

        $notify_url = $request->root(true) . '/api/recharge/epay';

        $auto_close = \app\common\model\Config::get(['name'=>'close_time'])->value*60;

        $expiretime = $order['createtime']+$auto_close;
        //$remark = '';
        $trxamt = $order['amount']*100;

        $data = [
            'cusid'=>$this->cusid,
            'appid'=>$this->appid,
            'version'=>'12',
            'trxamt'=>(string)$trxamt,
            'reqsn'=>$reqsn,
            'expiretime'=>date('YmdHis',$expiretime),
            'notify_url'=>$notify_url,
            'body'=>'订单号:'.$reqsn,
            //'remark'=>$remark,
            'validtime'=>'30',
            'paytype'=>'W06',
            'limit_pay'=>'no_credit',
            //'multipay'=>'1',
            //'asinfo'=>'',
            'randomstr'=>Random::alnum(32),
            //'subbranch'=>$this->subbranch,
            'signtype'=>'RSA',
            //'isdirectpay'=>1,
            //'ishideshare'=>1,
            //'isdirectback'=>1,
            //'idno'=>$idno,
            //'truename'=>$truename,
        ];

        $util = new AppUtil();

        $sign = $util::Sign($data,$this->cusRsaPrivateKey);

        $data['sign'] = $sign;

        return $data;
    }

}